$(function() {
    init();

    function init() {
        eventList();
    }

    function eventList() {
        $("#login_btn").on("tap", function() {
            var user_txt = $("#user_txt").val().trim();
            var pwd_txt = $("#pwd_txt").val().trim();
            if (!user_txt || !$.checkPhone(user_txt)) {
                mui.toast("手机号不合法");
                // console.log(123);
                return;
            }
            if (!pwd_txt || pwd_txt.length < 6) {
                mui.toast("密码不合法");
                return;
            }
            var params = {
                username: user_txt,
                password: pwd_txt
            };
            $.post(location.origin + "/user/login", params, function(ret) {
                if (ret && ret.success) {
                    mui.toast("登录成功");
                    setTimeout(function() {
                        location.href = "./index.html";
                    }, 2000);
                } else {
                    mui.toast(ret.message);
                }
            })
        })
    }
})